package com.example.sekerim;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.database.DatabaseHandler;
import com.example.database.WeightStorage;

public class HomePageFragment extends ListFragment {

	private TextView mTextView;
	private ArrayList<String> mSuggestions = new ArrayList<String>();;
	private Patient patient = new Patient();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		for (int i=0; i<30; i++)
			mSuggestions.add(String.valueOf(i));

		ArrayAdapter<String> adapter =
				new ArrayAdapter<String>(getActivity(),
						android.R.layout.simple_list_item_1,
						mSuggestions);
		setListAdapter(adapter);

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {             
		View rootView = inflater.inflate(R.layout.fragment_home_page, container, false);

		try {
			patient = (Patient) InternalStorage.readObject(getActivity(), Constants.shared_info);
		} catch (ClassNotFoundException e) {
			Log.e("While reading", e.getMessage());
		} catch (IOException e) {
			Log.e("While reading", e.getMessage());
		}

		mTextView = (TextView) rootView.findViewById(R.id.edit_text);

		DatabaseHandler db = new DatabaseHandler(getActivity());

		Log.d("Reading:", "Reading all weights"); 
		List<WeightStorage> contacts = db.getAllContacts();       

		String log = "";
		for (WeightStorage cn : contacts) {
			log += cn.getWeight() + " " + cn.getDate();
			// Writing Contacts to log
			Log.d("Name: ", log);
		}

		String s = patient.getUserName() + "\n" +
				patient.getPassword() + "\n" +
				patient.getUserSurname() + "\n" +
				"isMale:" + patient.isMale() + "\n" +
				patient.getBirthdayDay() + "/" + patient.getBirthdayMonth() + "/" + patient.getBirthdayYear() + "\n"
				+ patient.getEthnicity() + "\n" +
				patient.getHeight()  + " " +  
				log + "\n" + 
				"isSickExist:" + patient.isFamilyHistoryClean() + "\n" +
				"isSmoking:" + patient.isSmoking() + "\n";
		mTextView.setText(s);

		return rootView;
	}



}
